<template>
	<div>
		<transition name="move">
		  <div class="menu-sidebar" v-if="isShow">
		  	<div class="menu-sidebar-hd bottom-1px">
		  		<div class="close" @click="closeScreenPen"><x-icon type="ios-arrow-left" size="24"></x-icon></div>
		  		<span class="title">筛选</span>
		  	</div>
		  	<div class="menu-sidebar-bd">

		  		<div class="top-label screen-part">
		  			<div class="part-section">
				  		<checker class="label-box clearfix" v-model="multis" type="checkbox" selected-item-class="item-selected">
					      <checker-item class="block-label" value="isNewGds">
					      	<span><x-icon class="check" type="ios-checkmark-empty" size="16"></x-icon>新品</span>
					      </checker-item>
					      <!-- <checker-item class="block-label" :value="仅看包邮">
					      	<span><x-icon class="check" type="ios-checkmark-empty" size="16"></x-icon>仅看包邮</span> -->
						    </checker-item>
						      <checker-item class="block-label" value="inStock">
						      <span><x-icon class="check" type="ios-checkmark-empty" size="16"></x-icon>仅看有货</span>
						    </checker-item>
						     <checker-item class="block-label" value="isSeckill">
						      <span><x-icon class="check" type="ios-checkmark-empty" size="16"></x-icon>促销商品</span>
						    </checker-item>
		      		</checker>
	      		</div>
		  		</div>	  		
		  		<div class="screen-part bottom-1px">
		  			<h3 class="screen-title">价格区间(元)</h3>
						<div class="part-section">
							<div class="from-to">
								<input class="min-price" v-model="minPrice" type="text" placeholder="最低价">
								<span></span>
								<input class="max-price" v-model="maxPrice" type="text" placeholder="最高价">
							</div>
						</div>
		  		</div>
		  		<split></split>
		  		<div class="screen-part" :class="{ 'bottom-1px': i != categoryAttrs.length - 1 }" v-for="(item, i) in categoryAttrs" :key="i">
		  			<div @click="handViewAttrs(i)" class="screen-part-top">
		  				<h3 class="screen-title">{{ item.specName }}</h3>
		  				<span v-if="item.categoryAttr[0].attrValues.length > 6" class="arrow" :class="{ 'arrow-up': viewAllAttrs, 'arrow-down': !viewAllAttrs }"></span>
		  			</div>
						<div class="part-section">
							<checker class="label-box clearfix" v-model="selAttrIds[i]" selected-item-class="item-selected">
					      <checker-item v-show="j < item.categoryAttr[0].viewlen" v-for="(label, j) in item.categoryAttr[0].attrValues" class="block-label" :key="j" :value="label._id">
					      	<span>
					      		<x-icon class="check" type="ios-checkmark-empty" size="16"></x-icon>
					      		{{ label.v }}
					      	</span>
					      </checker-item>
		      		</checker>
						</div>
		  		</div>
		  	</div>
		  	<!-- 按钮 -->
		  	<div class="handle-bths top-1px">
		  		<span @click="reset" class="reset">重置</span>
		  		<span @click="submit" class="submit">确定</span>
		  	</div>
		  </div>
	  </transition>
	  <transition name="fade">
		  <div class="mask" v-if="isShow" @click="closeScreenPen"></div>
		</transition>
	</div>
</template>

<script>
import { Group, Cell, Checker, CheckerItem } from 'vux'	
import Split from '@/components/public/Split'
import http from '@/utils/http'

export default {
	components: {
		Checker,
		CheckerItem,
		Group,
		Cell,
		Split
	},
  data () {
  	return {
  		isShow: false,
  		priceCheck: '',
  		multis: [],
  		viewAllAttrs: false,
  		isViewAllLen: 3,
  		categoryAttrs: [],
  		selAttrIds: [],
  		minPrice: '',
  		maxPrice: ''
  	}
  },
  methods: {
  	reset () {
  		this.minPrice = ''
  		this.maxPrice = ''
  		this.multis = []
  		this.selAttrIds = []
  	},
  	submit () {
  		let filterSelAttrIds = []
  		this.selAttrIds.forEach(item => {
  			if (item) {
  				filterSelAttrIds.push(item)
  			}
  		})
  		this.$emit('filters', 
  		{ 
  			multis: this.multis, 
  			selAttrIds: filterSelAttrIds,
  			minPrice: this.minPrice,
  			maxPrice: this.maxPrice 
  		})
  		this.isShow = !this.isShow
  	},
  	closeScreenPen () {
  		this.isShow = !this.isShow
  	},
  	handViewAttrs (index) {
  		this.viewAllAttrs = !this.viewAllAttrs
  		if (!this.viewAllAttrs) {
  			this.categoryAttrs[index].categoryAttr[0].viewlen = 6
  		}else {
  			let len = this.categoryAttrs[index].categoryAttr[0].attrValues.length
  			this.categoryAttrs[index].categoryAttr[0].viewlen = len
  		}
  	},
  	// 获取分类属性
  	getCategoryAttrs () {
  		let categoryId = this.$route.query.cid
  		http.get('/api/v1/getCategoryAttrs', { categoryId }, false, res => {
  			if (res.status == 1) {
  				this.categoryAttrs = res.data.map(item => {
  					item.categoryAttr[0].viewlen = 6
  					return item
  				})
  				this.selAttrIds.length = this.categoryAttrs.length;
  				console.log(this.selAttrIds)
  			}
  		})
  	}
  },
  mounted () {
  	this.getCategoryAttrs()
  }
}
</script>

<style scoped>
.menu-sidebar {
	position: fixed;
	top: 0;
	bottom: 0;
	right: auto;
	width: 91%;
	max-width: 640px;
	margin-left: 30px;
	background: #fff;
	z-index: 105;
}
.menu-sidebar-hd {
	display: flex;
	height: 43px;	
	padding: 0 15px;
	line-height: 43px;
}
.close {
	flex: 0 0 24px;
	width: 24px;
	margin-left: -10px;
}
.close svg {
	fill: #999;
	line-height: 43px;
	height: 43px;
}
.menu-sidebar-hd .title {
	flex: 1;
	padding-right: 14px;
	text-align: center;
	color: #333;
}
.move-enter-active {
  transition: all .3s;
  transform: translateX(0);
}
.move-leave-active {
  transition: all .3s;
  transform: translateX(100%);
}
.move-enter,
.move-leave {
  transform: translateX(100%);
}
.mask {
	position: fixed;
	top: 0;
	bottom: 0;
	width: 100%;
	max-width: 640px;
	background: rgba(0, 0, 0, .5);
	z-index: 104;
}
.fade-enter-active {
  transition: all .3s;
  opacity: 1;
}
.fade-leave-active {
  transition: all .3s;
  opacity: 0;
}
.fade-enter,
.fade-leave {
  opacity: 0;
}
.menu-sidebar-bd {
	position: absolute;
	top: 43px;
	bottom: 42px;
	left: 0;
	right: 0;
	overflow-y: auto;
	overflow-x: hidden;
}
.menu-sidebar-hd.bottom-1px:after {
	border-color: #e0e0e0;
	bottom: 0;
}
.screen-part {
	padding: 0 15px;
}
.screen-part-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding-top: 15px;
}
.arrow {
  display: inline-block;
  height: 8px;
  width: 8px;
  border-width: 1px 1px 0 0;
  border-color: #c8c8cd;
  border-style: solid;
  position: relative;
}
.arrow-down {
	transform: matrix(.71,.71,-.71,.71,0,0) rotate(90deg);
	margin: -6px 2px 0 0;
}
.arrow-up {
	transform: matrix(.71,.71,-.71,.71,0,0) rotate(-90deg);
	margin: 4px 2px 0 0;
}
.screen-title {
  padding-right: 10px;
  color: #252525;
  font-size: 15px;
  line-height: 15px;
}
.part-section {
	padding: 15px 0;
}
.label-box {
	margin: 0 -10px -10px 0;
}
.block-label {
	float: left;
	height: 29px;
  width: 33%;
  color: #232326;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-right: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}
.block-label span {
  height: 28px;
  display: block;
  padding-left: 4px;
  padding-right: 4px;
  text-align: center;
  line-height: 28px;
  background-color: #f0f2f5;
  border: 1px solid #f0f2f5;
  border-radius: 5px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-sizing: border-box;
}
.check {
	position: relative;
	display: inline-block;
	vertical-align: middle;
	margin-top: -4px;
	display: none;
	fill: #f23030;
}
.item-selected {
	color: #f23030;
}
.item-selected span {
	border: 1px solid #f23030;
	background: #fff;
}
.item-selected .check {
	display: inline-block;
}
.from-to {
	display: flex;
	align-items: center;
	overflow: hidden;
	padding-bottom: 10px;
}
.from-to span {
	flex: 0 0 auto;
	width: 10px;
	border-top: 1px solid #666;
	margin: 0 5px;
}
.from-to input {
	flex: 1;
  display: block;
  background-color: #f0f2f5;
  height: 28px;
  line-height: 28px;
  border-radius: 5px;
  text-align: center;
  font-size: 12px;
  overflow: hidden;
  outline: none;
  padding: 0 10px;
}
.handle-bths {
	position: absolute;
	bottom: 0;
	width: 100%;
	left: 0;
	display: flex;
	z-index: 10;
	background: #fff;
}
.handle-bths span {
	flex: 1;
	font-size: 14px;
	text-align: center;
	line-height: 42px;
}
.handle-bths span.submit {
	color: #fff;
	background: #f23030;
}
</style>
